import React from 'react'
import PageTitle from 'components/page-title/index.jsx'
import {Link} from 'react-router-dom'
import Statistic from 'service/statistic-service.jsx'
import './index.css'

let _Statistic=new Statistic()

class Home extends React.Component{
  constructor(props) {
    super(props)
    this.state= {
      userCount: 0,
      productCount: 0,
      orderCount: 0
    }
  }
  componentDidMount () {
    this.loadCount()
  }
  loadCount () {
    _Statistic.getCount().then( res=>{
      this.setState(res)
    })
  }
  render () {
    return (
      <div className="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div className="row">
          <div className="col-md-12">
            <PageTitle title="首页" />
          </div>
          <hr/>
        </div>
        <div className="row info-wrapper">
          <div className="col-md-4 user-base">
            <Link to="/user">
              <p>{this.state.userCount}</p>
              <p>user</p>
            </Link>
          </div>
          <div className="col-md-4 product-base">
            <Link to="/product">
              <p>{this.state.productCount}</p>
              <p>product</p>
            </Link>
          </div>  
          <div className="col-md-4 order-base">
            <Link to="/order">
              <p>{this.state.orderCount}</p>
              <p>order</p>
            </Link>
          </div>   
        </div>            
      </div>    
    );
  }
}

export default Home;